/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package uk.ac.rdg.resc.mmd.colocation;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import org.joda.time.DateTime;

/**
 *
 * @author Alastair
 */
public class ObsProxyData {

    private List<Float> lats;
    private List<Float> lons;
    private List<DateTime> dates;
    private List<Float> values;
    private SortedMap<DateTime, Float> data;

    public ObsProxyData (InputStream in) throws IOException {
        InputStreamReader isr = new InputStreamReader(in);
        BufferedReader reader = new BufferedReader(isr);

        String line = null;

        this.lats = new ArrayList<Float>();
        this.lons = new ArrayList<Float>();
        this.dates = new ArrayList<DateTime>();
        this.values = new ArrayList<Float>();

        while((line = reader.readLine()) != null) {
            String[] tokens = line.split(",");
            lons.add(Float.parseFloat(tokens[0].trim()));
            lats.add(Float.parseFloat(tokens[1].trim()));
            int year = Integer.parseInt(tokens[2].trim());
            int month = Integer.parseInt(tokens[3].trim());
            dates.add(new DateTime(year, month, 15, 0, 0, 0, 0));
            values.add(Float.parseFloat(tokens[4].trim()));
        }

        this.data = new TreeMap<DateTime, Float>();
        for (int i = 0; i < dates.size(); i++) {
            data.put(dates.get(i), values.get(i));
        }
    }

    public float getLon() {
        return this.lons.get(0);
    }

    public float getLat() {
        return this.lats.get(0);
    }

    public List<DateTime> getDates() {
        return this.dates;
    }

    public List<Float> getValues() {
        return this.values;
    }

    public SortedMap<DateTime, Float> getData() {
        return this.data;
    }

}
